﻿@inherits BaseForm<TItem>
@typeparam TItem where TItem : class, new()

<ValidateForm @ref="_form" Model="Model.Data" class="boot-form">
    @if (Model.Rows != null && Model.Rows.Count > 0)
    {
        foreach (var row in Model.Rows)
        {
            var col = 12 / row.Fields.Count;
            var colSpan = $"boot-col col-{col}";
            <div class="boot-row row">
                @foreach (var field in row.Fields)
                {
                    <div class="@colSpan">
                        @* <label>@field.Column.Name</label> *@
                        <KField Model="field" />
                    </div>
                }
            </div>
        }
    }
</ValidateForm>

@code {
    private ValidateForm _form;

    protected override async Task OnInitFormAsync()
    {
        await base.OnInitFormAsync();
        Model.Initialize();
    }

    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
            Model.OnValidate = _form.Validate;
        base.OnAfterRender(firstRender);
    }
}